package com.blkj.iam.common.util;

import jakarta.validation.constraints.NotNull;

import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.security.cert.X509Certificate;

/**
 * @author Ethan
 * createTime 2024/10/31 08:44
 * description
 * version 1.0
 */
public class UnsafeSSLContext {

    @NotNull
    public static SSLContext createUnsafeSSLContext() throws Exception {
        SSLContext sc = SSLContext.getInstance("TLS");
        TrustManager[] trustAllCerts = new TrustManager[]{
                new X509TrustManager() {
                    @Override
                    public X509Certificate[] getAcceptedIssuers() {
                        return null;
                    }

                    @Override
                    public void checkClientTrusted(X509Certificate[] certs, String authType) {
                    }

                    @Override
                    public void checkServerTrusted(X509Certificate[] certs, String authType) {
                    }
                }
        };
        sc.init(null, trustAllCerts, new java.security.SecureRandom());
        return sc;
    }
}
